import 'package:flutter/material.dart';
import 'package:get/get.dart';

class UiDelay extends StatefulWidget {
  const UiDelay({
    super.key,
    this.time = 0.3,
    required this.child,
    this.placeholder,
  });
  final num time;
  final Widget child;
  final Widget? placeholder;
  @override
  State<UiDelay> createState() => _UiDelayState();
}

class _UiDelayState extends State<UiDelay> {
  bool visible = false;
  num time = 0;
  @override
  void initState() {
    time = widget.time;
    show();
    super.initState();
  }

  show() async {
    await time.delay();
    if (mounted) {
      setState(() {
        visible = true;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: visible ? widget.child : widget.placeholder,
    );
  }
}
